module FloatConverter {

	provides interface FloatConverterIF;
}
implementation {

	union {
		uint32_t theBytes;
		float aFloat;
	} funion;

	async command uint32_t FloatConverterIF.convFloat_uint32_t(float * val) {
		/*unsigned char bArray[4];
		unsigned char * p = (unsigned char * ) val;
		uint32_t float32b;
		int i = 0;
		for(i = sizeof(float) - 1; i >= 0; i--) {
			bArray[i] = *p;
			p++;
		}

		float32b = 0x0000;
		float32b |= bArray[0]& 0xFF;
		float32b <<= 8;

		float32b |= bArray[1]& 0xFF;
		float32b <<= 8;

		float32b |= bArray[2]& 0xFF;
		float32b <<= 8;

		float32b |= bArray[3]& 0xFF;
		*/
		uint32_t float32b;
		atomic funion.aFloat = *val;
		atomic float32b = funion.theBytes;
		
		return float32b;
	}

	async command float FloatConverterIF.convInt32_tFloat(uint32_t * val) {

		
		float aFloat;
		/*
		uint32_t * pBytes;

		pBytes = (uint32_t * )&aFloat;
		pBytes[0] = val[0];
		pBytes[1] = val[1];
		pBytes[2] = val[2];
		pBytes[3] = val[3];*/
		atomic funion.theBytes = *val;
		atomic aFloat = funion.aFloat;


		return aFloat;
	}

}